<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Python 的安装 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Python 的安装</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Python/">Python</a>
			</span>
		
	</div>

	

	
		<h1 id="Python-的安装"><a href="#Python-的安装" class="headerlink" title="Python 的安装"></a>Python 的安装</h1><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://www.python.org/" target="_blank" rel="external">python 官网</a></p>
<h2 id="1-linux-的-python-安装"><a href="#1-linux-的-python-安装" class="headerlink" title="1. linux 的 python 安装"></a>1. linux 的 python 安装</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CentOS 6.5 系统自带 Python 2.6 </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># rpm -q python</span></div><div class="line">python-2.6.6-51.el6.x86_64</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CentOS 7.0 系统自带 PYthon 2.7</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># rpm -q python</span></div><div class="line">python-2.7.5-48.el7.x86_64</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 linux 系统下，直接输入 python 就可以进入 pyhton 的命令行模式，使用  <code>exit（）</code> 退出</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># python</span></div><div class="line">Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) </div><div class="line">[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2</div><div class="line">Type <span class="string">"help"</span>, <span class="string">"copyright"</span>, <span class="string">"credits"</span> or <span class="string">"license"</span> <span class="keyword">for</span> more information.</div><div class="line">&gt;&gt;&gt; <span class="built_in">print</span> <span class="string">'hello world'</span></div><div class="line">hello world</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;原生的 python 带的命令行不是很多，也不能使用 tab 键命令补齐。这时候需要安装一个 python shell 模块，叫 “ipython” 的模块，就可以进行命令补齐。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果计算机可以上网，那么可以直接使用网络安装，使用 命令 pip ，如果没有这个命令，需要先安装，需要先安装 epel 扩展源</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># yum install -y python-pip</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装完成后再安装 ipython</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># pip install ipython</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;因为 CentOS 6.5 自带的 python 为 2.6 版本比较底，直接 pip 安装有可能高版本会报错，需要在包名后边加上低版本版本号，来安装较低版本。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># pip install ipython==1.2.1</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看安装模块命令 <code>pip list</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># pip list</span></div><div class="line">You are using pip version 7.1.0, however version 9.0.1 is available.</div><div class="line">You should consider upgrading via the <span class="string">'pip install --upgrade pip'</span> <span class="built_in">command</span>.</div><div class="line">argparse (1.2.1)</div><div class="line">distribute (0.6.10)</div><div class="line">iniparse (0.3.1)</div><div class="line">ipython (1.2.1)</div><div class="line">pip (7.1.0)</div><div class="line">pycurl (7.19.0)</div><div class="line">pygpgme (0.1)</div><div class="line">pyxdg (0.18)</div><div class="line">setuptools (0.6rc11)</div><div class="line">urlgrabber (3.9.1)</div><div class="line">yum-metadata-parser (1.1.2)</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装完成，直接输入 ipython 就可以进如 python 命令行模式的，这个模式下可以使用 tab 键进行命令补齐了，退出使用命令 <code>exit</code> </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># ipython</span></div><div class="line">Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) </div><div class="line">Type <span class="string">"copyright"</span>, <span class="string">"credits"</span> or <span class="string">"license"</span> <span class="keyword">for</span> more information.</div><div class="line"></div><div class="line">IPython 1.2.1 -- An enhanced Interactive Python.</div><div class="line">? -&gt; Introduction and overview of IPython<span class="string">'s features.</span></div><div class="line"><span class="string">%quickref -&gt; Quick reference.</span></div><div class="line"><span class="string">help -&gt; Python'</span>s own <span class="built_in">help</span> system.</div><div class="line">object? -&gt; Details about <span class="string">'object'</span>, use <span class="string">'object??'</span> <span class="keyword">for</span> extra details.</div><div class="line"></div><div class="line">In [1]:</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装 ipython 报错</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/02.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># yum install -y python-devel</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果机器不能上网，那么需要在可以上网的机器上下载安装包拷贝到机器上安装。<a href="https://pypi.python.org/pypi/ipython" target="_blank" rel="external">下载地址</a><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后拷贝到机器解压</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/03.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压以后有个 setup.py 脚本</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/04.png?raw=true" alt="iamges"><figcaption class="figure__caption">iamges</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用命令 setup.py install 安装，安装完成使用 <code>pip list</code> 查看是否安装成功。</p>
<h2 id="2-windows-安装-python-（只需要了解即可）"><a href="#2-windows-安装-python-（只需要了解即可）" class="headerlink" title="2.windows 安装 python （只需要了解即可）"></a>2.windows 安装 python （只需要了解即可）</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先在<a href="https://www.python.org/" target="_blank" rel="external">Python官网</a> 下载 python 安装包</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/05.png?raw=true" alt="iamges"><figcaption class="figure__caption">iamges</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下载安装以后，c 盘下会有一个 python 文件夹</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/06.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/07.png?raw=true" alt="iamges"><figcaption class="figure__caption">iamges</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后把 python 路径加入 windows 的环境变量</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/08.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/09.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/10.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/11.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;进入 cmd 命令行模式，输入 python 就可以进入 python 命令行模式</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/python%E5%AE%89%E8%A3%85/12.png?raw=true" alt="iagmes"><figcaption class="figure__caption">iagmes</figcaption></figure></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Python/1. Python 基础篇/1. Python 基础语法/1.2 Python 的安装/2. Python 的安装/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
